﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using WPFExcelReport.Helpers;
using System.ComponentModel;
 
namespace WPFExcelReport
{
    public partial class TAB55
    {
     
       
        public TAB55()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VABPOS();
            DataContext = MV;
            InitializeComponent();
           
        }
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            if (IsLoaded)
                return;
            base.Window_Loaded(sender, e);
            FTAUTOSUM = true;
            TCOUNT1 = "单数";
            TKEY1 = "计划";
            KEY1 = "ABPSOLLMENGE1";
            SKEY1 = "ABPAUFKRS";
            TKEY2 = "实际M";
            KEY2 = "ABPEALFM";
            SKEY2 = "ABPAUFKRS";
        }

      public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            if (app.company == "JLT")
            {
                if (dwMaster != null)
                {
                    MATART = "K" + dwMaster["ABPART"].ToString()
                        + dwMaster["ABPVAR"].ToString()
                        + dwMaster["ABPFARBE"].ToString() + dwMaster["ABPBESCHICH"].ToString()
                        + dwMaster["ABPDESS"].ToString() + dwData["ABPCOLORIT"].ToString();
                }
                else
                {
                    MATART = "";
                }

            }
        }
        public override void OnEXAUFChg(string art)
        {
            if (!IsAuto)
                return;
            TBMain.Clear();
            if (art.Length < 63)
                return;
            dwData = TBMain.NewRow();
            dwData["ABPMANDANT"] = app.Mandant;
            dwData["ABPWAKZ"] ="R";
            dwData["ABPART"] = art.Substring(1, 20);
            dwData["ABPVAR"] = art.Substring(21, 2).PadRight(3);
            dwData["ABPFARBE"] = art.Substring(23, 10);
            dwData["ABPBESCHICH"] = "".PadRight(10);
            dwData["ABPDESS"] = "".PadRight(10);
            dwData["ABPCOLORIT"] = "".PadRight(10);
            SResult = TMV.QABP40(dwData);
            MergeData(SResult, true);
            base.OnEXAUFChg(art);
        }
        public override void OnAutoChg(bool value)
        {
            OnEXAUFChg(EXAUF);
            base.OnAutoChg(value);
        }
        public void Load()
        {
            if (vm == null)
                return;
            if (AUF == null)
                return;
            if (AUF.Length < 1)
                return;
            DataRow dwData =TBMain.NewRow();
            string ordertype = Helpers.Helper.Left(AUF, 1);
            dwData["ABPMANDANT"] = app.Mandant;
            dwData["ABPAUFKRS"] = AUF.Substring(1, 2);
            dwData["ABPAUFLFD"] = AUF.Substring(3, 6);
            dwData["ABPAUFPOS"] = AUF.Substring(9, 3);   
            DataSet SResult = TMV.QueryABPOS(dwData, 31);
            MergeData(SResult,true);
            MessageInfo msgs = new MessageInfo();
            string msg = "";
            msgs.MSGTYPE = "JOBADD";
            msgs.Sender = this.RUNID;
            msgs.ACTION = "JOBADD";
            msgs.AUFTYP = "V";
            foreach (DataRow row in TBMain.Rows)
            {
                msgs.KRS = row["ABPAUFKRS"].ToString();
                msgs.LFD = row["ABPAUFLFD"].ToString();
                msgs.POS = row["ABPAUFPOS"].ToString();
                msgs.P1 = row["ABPAUFART"].ToString();
                msgs.P2 = row["ABPPOSTYP"].ToString();
                VICC_WFEVENTS.SVWF.CheckEvents("UIMESSAGE", dwMaster, msg, msgs);
            }
        } 

        private void ShowDetail_Click(object sender, RoutedEventArgs e)
        {
            if (!IsShowOutPut)
            {
                IsShowOutPut = true;
                return;
            }
            IsShowOutPut = false;
        }
    }
}
